<template>
  <div>
    <el-dialog title="编辑限时活动" :visible.sync="dialogTableVisible1">
      <el-row>
        <el-col :span="6">商品原价: {{ goodsData.price }}</el-col>
        <el-col :span="18">商品名称: {{ goodsData.name }}</el-col>
      </el-row>
      <el-row style="margin-top: 30px">
        <el-col :span="12"
          >促销价格:
          <el-input-number
            v-model="originalPrice"
            @change="priceChange"
            :min="10"
            :max="1000000"
            label="促销价格"
            size="small"
          ></el-input-number
        ></el-col>
        <el-col :span="12"
          >排序:
          <el-input-number
            v-model="orderNum"
            @change="orderChange"
            :min="1"
            :max="1000"
            label="排序"
            size="small"
          ></el-input-number
        ></el-col>
      </el-row>
      <el-row style="margin-top: 30px">
        <el-col :span="3" style="line-height: 40px">开始结束时间</el-col>
        <el-col :span="21">
          <el-date-picker
            v-model="time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-col>
      </el-row>

      <el-row style="margin-top: 30px">
        <el-col :span="12" style="line-height: 40px">
          <span>活动限购数量</span>
          <el-input
            style="width: 200px; margin-left: 10px"
            v-model="buyCount"
            placeholder="请输入数量"
          ></el-input>
        </el-col>
      </el-row>

      <el-row style="margin-top: 30px">
        <el-col :span="2" style="line-height: 40px">
          <span>商品图片</span>
        </el-col>
        <el-col :span="12">
          <img
            style="width: 150px; height: 150px"
            :src="goodsData.pic"
            alt=""
          />
        </el-col>
      </el-row>
      <el-row style="margin-top: 30px">
        <el-col :span="2">
          <el-button type="primary" @click="addGoods">确认</el-button>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" @click="cancel" plain>取消</el-button>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import marketingApi from "@/api/marketing/index";
export default {
  components: {},

  data() {
    return {
      time: "",
      buyCount: "",
      originalPrice: "",
      orderNum: "",
      goodsData: [],
      dialogTableVisible1: false,
      goodsId: "",
    };
  },

  created() {},

  mounted() {},

  methods: {
    // 取消添加
    cancel() {
      this.dialogTableVisible1 = false;
    },
    // 确认添加促销商品
    addGoods() {
      console.log(this.i);
      this.$confirm("是否将此商品设为热销, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        marketingApi
          .addRecommend({
            productId: this.goodsId,
            // promotionEndTime: this.time[1],
            // promotionEndTime: "2020-12-22 00:00:00",
            promotionPerLimit: this.buyCount,
            promotionPrice: this.originalPrice,
            // promotionStartTime: this.time[0],
            // promotionStartTime: "2020-12-16 00:00:00",
            sort: this.goodsData.sort,
            publishStatus: 1,
          })
          .then((res) => {
            console.log(res);
            if (res.success) {
              this.dialogTableVisible1 = false;
              this.dialogTableVisible = true;
              this.buyCount = 1;
              this.init();
            } else {
            }
          });
      });
    },
  },

  computed: {},

  watch: {},
};
</script>

<style scoped lang='scss'>
</style>